home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / kant-generator-04-c / Kant ƒ / Shell ƒ / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  1.9 KB  |  59 lines  |  [TEXT/MMCC]

  1. #include "error.h"
  2. #include "main.h"
  3. #include "dialogs.h"
  4. #include "environment.h"
  5.  
  6. NMRec            gMyNotification;
  7. enum ErrorTypes    gPendingResultCode;
  8.  
  9. void FailNilUPP(UniversalProcPtr theUPP)
  10. {
  11.     if (theUPP == nil)
  12.         HandleError(kNoMemory, FALSE);
  13. }
  14.  
  15. void HandleError(enum ErrorTypes resultCode, Boolean exitToShell)
  16. /* if we're in the foreground, just get the error string (from the .rsrc file) and
  17.    display the error alert; otherwise, we have to queue it, put up a notification
  18.    (if possible), and wait patiently to come back in the foreground.  (see main.c,
  19.    DispatchEvents(), case osEvt. */
  20. /* All error codes are listed in program globals.h */
  21. {
  22.     Str255            tempStr;
  23.     Handle            myResHand;
  24.     
  25.     /* if there is no error, or the error is that the user cancelled an operation
  26.        in progress, don't display anything; it would only confuse them. */
  27.     if ((resultCode==userCancelErr) || (resultCode==allsWell)) return;
  28.     
  29.     if (gIsInBackground)    /* if program is in background, can't display alert immed. */
  30.     {
  31.         if (gHasNotificationManager)    /* if they don't have notification, f*ck 'em */
  32.         {
  33.             myResHand=GetResource('SICN', 1234);    /* small icon for menu bar flashing */
  34.             gMyNotification.qType=nmType;            /* for more detail on these params, */
  35.             gMyNotification.nmMark=1;                /* see IM Processes, 5-8 */
  36.             gMyNotification.nmIcon=myResHand;
  37.             gMyNotification.nmSound=(Handle)-1L;
  38.             gMyNotification.nmStr=0L;
  39.             gMyNotification.nmResp=0L;
  40.             gMyNotification.nmRefCon=0L;
  41.             NMInstall(&gMyNotification);
  42.         }
  43.         gPendingResultCode=resultCode;                /* remember error code for later */
  44.     }
  45.     else
  46.     {
  47.         GetIndString(tempStr, 129, resultCode);    /* get error string from .rsrc */
  48.         ParamText(tempStr, "\p", "\p", "\p");
  49.         PositionDialog('ALRT', largeAlert);        /* position alert (see dialogs.c) */
  50.         StopAlert(largeAlert, 0L);                /* show it */
  51.     }
  52.     
  53.     if (exitToShell)        /* for fatal errors */
  54.     {
  55.         ShutDownEnvironment(FALSE);
  56.         ExitToShell();
  57.     }
  58. }
  59.